<?php
namespace app\admin\controller;


use app\admin\model\Admin;
use app\admin\model\Alipay;
use app\admin\model\JingFen;
use app\admin\model\MerchSetplus;
use think\facade\View;
use think\facade\Session;

class Login
{
    public function index()
    {
        Session::delete('health_admin');
        return View::fetch();
    }

    public function check()
    {
        $username = input('post.username');
        $password = input('post.password');

        // 在此处添加检查用户名和密码的逻辑，省略...

        $info = Admin::where('username', $username)->find();
        if($info){
            if($info['password'] == $password){
                // 如果用户名和密码验证通过，则将用户信息保存到Session中
                Session::set('health_admin', [
                    'id'=>  $info['id'],
                    'username' => $username,
                    'password' => $password,
                    'groupid'=>$info['group_id'],
                ]);
                Session::save();
                $arr['status'] = 1;
                $arr['url'] = 1;//dd($arr);
                return json($arr);
            }else{
                $arr['status'] = 0;
                $arr['msg'] = '密码错误';
                return json($arr);
            }
        }else{
            $arr['status'] = 0;
            $arr['msg'] = '该管理员不存在';
            return json($arr);
        }



//        dd(Session::get('merchant'));

        // 跳转到首页
//        return redirect(url('merchant/index/index'));
    }

    public function test(){
        (new MerchSetplus())->balance();
//        $info['card_no'] = '6214832349601869';
//        $info['real_name'] = '庄延超';
//        (new MerchSetplus())->virtPay($info,1,'WTD2023022316771261381995');

//        (new MerchSetplus())->checkWithdraw('WTD2023022316771261381995');
    }

    public function test2(){
//        (new Alipay())->transferToCard();
        (new Alipay())->transToaccount();
//        (new Alipay())->transTobank2();
    }

    public function test3(){
//        $res = (new JingFen())->accountBookQuery('2088930736068477');
//        dd($res);

        //            'trueName' => '庄延超',//银行卡姓名
//            'certno' => '44080319870804393X',//身份证号
//            'mobile' => '18028432514',//银行卡预留手机号
//            'cardno' => '6228480626748032275',//银行卡卡号
//            'bankno' => '103100000026',//银行卡卡号
//            'bankName' => '中国农业银行',//银行名称
        $order_id = '111';
        $platform = 0;
        $title = '测试';
        $amount = '0.01';
        $payeeIdentity = '6228480626748032275';
        $payeeName = '庄延超';
        $payeeType = 3;
        $payerIdentity = '2088930736068477';
        $payerName = '四川云尚优品电子商务有限公司';
        $payerType = 100;
        $remark = '';
        $extInfo = [
            'inst_name'=>'中国农业银行',
            'account_type'=>2
        ];
        $extInfo = json_encode($extInfo);
        $res = (new JingFen())->payment2($order_id, $platform, $title, $amount, $payeeIdentity, $payeeName, $payeeType, $payerIdentity, $payerName, $payerType, $remark, $extInfo);
        dd($res);
    }

    public function charge(){
        (new Alipay())->transToaccount2();
    }

    public function charge3(){
        (new Alipay())->transToaccount3();
    }

    public function charge4(){
        (new Alipay())->transToaccount4();
    }
}